package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Permission;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IPermissionService;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    IPermissionService permissionService;

    @RequestMapping("/list")
    @RequiredPermission({"权限列表","permission:list"})
    public String list(QueryObject qo, Model model){
        model.addAttribute("result",permissionService.query(qo));
        return "permission/list";
    }


    @RequestMapping("/delete")
    @RequiredPermission({"权限删除","permission:delete"})
    public String delete(Long id){
        permissionService.delete(id);
        return "redirect:/permission/list.do";
    }

    @RequestMapping("/reload")
    @RequiredPermission({"权限加载","permission:reload"})
    public String reload(){
        permissionService.reload();
        return "redirect:/permission/list.do";
    }


}
